package cn.sofwin.day0204;

import java.io.File;
import java.io.IOException;

public class Test {
    static String root = "D:/dev/java/works/java2021/src/cn/sofwin/day0204/test/";

    public static void main(String[] args) throws IOException {
        // 创建文件
        // createFile();

        // 创建文件夹
        //createFolder();

        // 文件重命名
        //renameFile();

        // delete
        deleteFile();
    }

    static void createFile() throws IOException {
        //
        String filePath = root + "abc.txt";

        File file = new File(filePath);

        file.createNewFile();
    }

    static void createFolder(){
        // 构建文件夹的路径
        String path = root + "hello";
        // 根据路径，创建文件夹对象
        File file = new File(path);
        // 创建文件夹
        // mkdir 要求父目录必须存在，否则报错
        // mkdirs 父目录可以不存在
        file.mkdirs();
    }

    static void renameFile(){
        String oldPath = root + "abc.txt";
        String newPath = root + "def.txt";

        File oldFile = new File(oldPath);
        File newFile = new File(newPath);

        oldFile.renameTo(newFile);
    }

    static void deleteFile(){
        String path = root + "def.txt";

        File file = new File(path);

        file.delete();
    }
}
